VSCode 中使用typescript檢視output - Code Runner套件


Posted by mijouhsieh on 2024-01-01

tsc hello.ts

指令意思是,用 typescript compiler 去執行TypeScript的編譯器,編譯hello.ts 檔案,會 產生 hello.js檔案

// hello.ts
// 相減函式
function subtract (num1:number, num2: number) {
  return num1-num2
}
const total = subtract(5,3)
console.log(total)
// hello.js
// 相減函式
function subtract(num1, num2) {
    return num1 - num2;
}
const total = subtract(5, 3);
console.log(total);

Q: 要在哪邊才看到 console.log(total)的輸出結果?

1 安裝VSCode套件

vscode-extension-code-runner.png

2 在js檔 右鍵Run Code快捷鍵: ctrl+alt+n 或 右上角三角形按鈕

就會出現OUTPUT,console結果會在[Running]區塊

vscode-extension-run-code.png


#code runner #VSCode extension







Related Posts

Vite 安裝

Vite 安裝

部署 (1) —— 建立 AWS EC2 主機及 SSH 連線

部署 (1) —— 建立 AWS EC2 主機及 SSH 連線

10. Decorator

10. Decorator


Comments